<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *客户列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'客户列表'),
);
$this->model('model')->checkjuese(7);
$juese_id=7;
$workerids=$this->model('model')->getworkerids($juese_id);
$return['stores']=$this->getall('store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
$return['workers']=$this->getall('worker',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
//客户列表
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=array();
	$params=array('worker'.$juese_id.'id'=>$workerids,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['jibie_type'] && $_RQ['jibie_type']!='all'){
		$params['jibie_type']=intval($_RQ['jibie_type']);
	}
	$return['params']['jibie_type']=$_RQ['jibie_type']?:'all';
	if($_RQ['status'] && $_RQ['status']!='all'){
		if($_RQ['status']==7){
			$params['ti7_time >']=100;
		}elseif($_RQ['status']=='t5liu_time'){
			$params['t5liu_time >']=100;
		}elseif($_RQ['status']=='t5wu_time'){
			$params['t5wu_time >']=100;
		}elseif($_RQ['status']=='t6liu_time'){
			$params['t6liu_time >']=100;
		}else{
			$params['status']=intval($_RQ['status']);
		}
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['storeid']){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if($_RQ['up_time']){
		$time_range=cfc('tools')->base64_decode($_RQ['up_time'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['up_time between']=array($time_range['tstart'],$time_range['tend']);
		$return['params']['up_time']=$time_range;
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:30;
	if($_RQ['psize']){
		$return['params']['psize']=$_RQ['psize'];
	}
	$list=pdo_getslice('jy_yxw_member',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=$this->model('member')->member_show($item['id']);
			if($item['from_type']==1){
				$item['from_typetitle']=$this->member_from1_type[$item['from1_type']];
			}elseif($item['from_type']==2){
				$item['from_typetitle']=$this->member_from2_type[$item['from2_type']];
			}else{
				$item['from_typetitle']=$this->member_from_type[$item['from_type']];
			}
			$item['up_time']=$item['up_time']?date('Y/m/d',$item['up_time']):'无';
			$genjin_log=pdo_get('jy_yxw_genjin_log',array('memberid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'remark','createtime desc');
			$item['genjinmsg']=$genjin_log['remark']?:'无任何根据记录';
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	//页面显示设置
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		//'export'=>'export',
		'list'=>array('data'=>'list','line_max_width'=>'900px','del_message'=>'确认删除该客户吗？','total'=>$total,'psize'=>$psize,'del_op'=>'del','del_one'=>false,'delall'=>false,'edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			//array('name'=>'storeid','title'=>'所属门店','type'=>'select','options'=>'stores'),
			/*array('name'=>'jibie_type','title'=>'客户级别','type'=>'radio','options'=>'jibie_type'),
			array('name'=>'from_typetitle','title'=>'渠道','type'=>'string'),
			array('title'=>'网络员','name'=>'worker3id','type'=>'select','options'=>'workers'),
			array('title'=>'前台专员','name'=>'worker4id','type'=>'select','options'=>'workers'),
			array('title'=>'电客员','name'=>'worker5id','type'=>'select','options'=>'workers'),
			array('title'=>'销售员','name'=>'worker6id','type'=>'select','options'=>'workers'),
			array('title'=>'体验员','name'=>'worker7id','type'=>'select','options'=>'workers'),
			array('title'=>'试用员','name'=>'worker8id','type'=>'select','options'=>'workers'),*/
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'up_time','title'=>'最近跟进时间','type'=>'string'),
			array('name'=>'genjinmsg','title'=>'最近跟进记录','type'=>'string','ishuan'=>1),
			//array('name'=>'createtime','title'=>'添加日期','type'=>'time'),
		),'action'=>array(
			//array('type'=>'href','op'=>'setgenjin_log','title'=>'处理电客情况','show'=>array('status'=>array(1,2,30,31))),
			//array('type'=>'href','op'=>'setgenjin_log6','title'=>'处理跟进情况','show'=>array('status'=>array(32,6,8))),
			array('type'=>'href','action'=>'jy_yxw/xiaoshou.setgenjin_log/set7/','title'=>'处理体验体用','show'=>array('status'=>array(5,6,40,42))),
			//array('type'=>'href','action'=>'jy_yxw/juese7.list/setgenjin_log8','title'=>'处理试用情况','show'=>array('status'=>array(7))),
			//array('type'=>'href','op'=>'setgenjin_log9','title'=>'处理成交情况','show'=>array('status'=>array(9))),
			//array('type'=>'modal','op'=>'setstatus4','title'=>'处理已意向','show'=>array('status'=>array(3))),
			//array('type'=>'modal','op'=>'worker6id','title'=>'分配销售员','show'=>array('status'=>4)),
			//array('type'=>'modal','op'=>'worker7id','title'=>'分配体验师','show'=>array('status'=>33)),
			//array('type'=>'modal','op'=>'worker8id','title'=>'分配试用员','show'=>array('status'=>34)),
			//array('type'=>'modal','op'=>'worker9id','title'=>'分配售后助理员','show'=>array('status'=>array(10,35))),
			array('type'=>'href','action'=>'/member.genjin_log/onelist/','title'=>'查看跟进记录'),
		),'batch'=>$batch),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'手机号','name'=>'mobile','help'=>''),
			array('type'=>'string','width'=>'15','title'=>'客户名称','name'=>'title','help'=>''),
			//array('name'=>'status','width'=>'15','title'=>'状态','type'=>'radio','options'=>'status2'),
			array('name'=>'up_time','width'=>15,'title'=>'时间段','type'=>'time_range')
		),
	);
	$return['status']=$this->model('member')->gestatus('all');
	$return['status2']=$this->model('member')->gestatus(7);
	$return['status2']['all']='全部';
	$return['jibie_type']=$this->member_jibie_type;
	$return['from_type']=$this->member_from_type;
	$return['from1_type']=$this->member_from1_type;
	$return['from2_type']=$this->member_from2_type;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='export'){
	//客户列表
	$return['params']=array();
	$params=array('worker'.$juese_id.'id'=>$workerids,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['jibie_type'] && $_RQ['jibie_type']!='all'){
		$params['jibie_type']=intval($_RQ['jibie_type']);
	}
	$return['params']['jibie_type']=$_RQ['jibie_type']?:'all';
	if($_RQ['status'] && $_RQ['status']!='all'){
		if($_RQ['status']==7){
			$params['ti7_time >']=100;
		}else{
			$params['status']=intval($_RQ['status']);
		}
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['storeid']){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	$list=pdo_getall('jy_yxw_member',$params,$fields);
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['jibie_type']=$this->member_jibie_type[$item['jibie_type']];
			$item['from_type']=$this->member_from_type[$item['from_type']];
			$item['status']=$this->member_status[$item['status']];
			$item['xueli']=$this->xueli_type[$item['xueli']];
		}
	}
	$header=array(
		'id'=>'客户ID',
		'title'=>'客户名称',
		'mobile'=>'手机号',
		'jibie_type'=>'级别',
		'from_type'=>'渠道',
		'xueli'=>'学历',
		'status'=>'状态',
		'createtime'=>'注册时间',
	);
	model('core/tools')->export2excel($header,$list,'客户数据');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			$this->model('member')->check_del($id,'xiaoshou');
			pdo_delete('jy_yxw_member',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}